<template>
  <div>
    <el-row>
        <b>注册时间：</b>
        <el-date-picker
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 250px;"
            v-model="formData.time"
            @click="initTable"
            >
        </el-date-picker>
        <el-button type="primary" icon="el-icon-search">查询</el-button>
    </el-row>
    <el-row>
        <b>业主电话：</b>
        <el-input style="width: 250px;" v-model="formData.phone"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="initTable">查询</el-button>
    </el-row>
    <el-row>
        <b>身份信息：</b>
        <el-radio-group v-model="formData.isRefine" @change="changeStatus">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">已完善</el-radio-button>
        <el-radio-button label="2">未完善</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <el-button type="info" plain icon="el-icon-upload2" @click="exportproperty">导出</el-button>
    </el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="业主编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="业主姓名">
      </el-table-column>
      <el-table-column
        prop="nickName"
        label="昵称">
      </el-table-column>
      <el-table-column
        prop="gender"
        label="性别">
        <template slot-scope="scope">
            <el-tag>{{ scope.row.gender == 1?"男":"女" }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="idCard"
        label="身份信息">
        <template slot-scope="scope">
            <el-tag effect="dark" :type="scope.row.isRefine == 1?'success':'danger'">{{ scope.row.isRefine == 1?"已完善":"未完善"}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        label="账号状态">
        <template slot-scope="scope">
            <el-tag effect="dark" :type="scope.row.status == 1?'success':'danger'">{{ scope.row.status == 1?"正常":"停用" }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="注册时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-search" @click="viewArticle(scope.row)">查看</el-button>
            <!-- <router-link :to="{ name: 'ownerInfo', params: { id: scope.row }}">Go to My Route</router-link> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
    name:'owner',
    data(){
        return{
            tableData: [],
            currentPage:1,
            pageSize:10,
            total:0,
            formData:{
              phone:'',
              isRefine:0,
              time:[]
            }
        }
    },
    created(){
      this.initAuthority()
    },
    methods:{
      initAuthority(){
        this.$request.get("/role/authority",{
          params:{
            id: JSON.parse(localStorage.getItem("admin")).id,
            index: 5
          }
        })
        .then(res =>{
          this.Authority = res.data
          if(res.data == '1'){
            this.initTable()
          }else{
            this.$message.error("你没有权限访问此功能")
            // this.$router.push("/")
          }
        })
        .catch(err =>{
          console.log(err)
        })

      },
        exportproperty(){
            window.open("http://192.168.1.6:8099/file/ownerExprot")
        },
      changeStatus(value){
            console.log(value)
            this.initTable()
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
            this.initTable()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.initTable()
        },
        initTable(){
            let startTime
            let endTime
            if(this.formData.time == null){
                startTime = ''
                endTime = ''
            }else{
                startTime = this.formData.time[0]
                endTime = this.formData.time[1]
            }

            this.$request.get("/owner/page",{
                params:{
                    page: this.currentPage,
                    size: this.pageSize,
                    isRefine: this.formData.isRefine,
                    startTime: startTime,
                    endTime: endTime,
                    phone:this.formData.phone
                }
            }).then(res => {
                // this.tableData = res.data.records
                const arr = res.data.records
                this.tableData = arr.filter(item => item.id !== "0000000001")
                this.total = res.data.total
            }).catch(err => {
                console.error('Err:',err)
            })
          },
          viewArticle(val){

            localStorage.setItem("owner",val.id)
            this.$router.push('ownerInfo')
          }
    }
}
</script>

<style>
 .el-row{
        margin-bottom: 20px;
    }
</style>